package org.douxiaoban.client.adapter;

import java.util.List;

import org.douxiaoban.client.R;
import org.douxiaoban.data.DouGroupTopicData;
import org.douxiaoban.data.DoubanBaseData;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;


/**
 * 豆瓣小组，最新，我回复，和我发表－
 * @author 6a209
 * 8:43:23 PM May 3, 2012
 */
public class DouGroupAdapter extends DoubanAdapter{

	
	private LayoutInflater mInflater;
	public DouGroupAdapter(Context context, List<? extends DoubanBaseData> list) {
		super(context, list);
		mInflater = LayoutInflater.from(context);
	}


	@Override
	public View getView(int position, View view, ViewGroup vGroup) {
		DouGroupTopicData topicData = (DouGroupTopicData)mListData.get(position);
		HandleView handleView = null;
		if(null == view){
			view = mInflater.inflate(R.layout.group_item, null);
			handleView = new HandleView();
			handleView.mTvTitle = (TextView)view.findViewById(R.id.group_item_title);
			handleView.mTvGroup = (TextView)view.findViewById(R.id.group_item_group_name);
			handleView.mTvAuthor = (TextView)view.findViewById(R.id.group_item_author);
			handleView.mTvReplyCount = (TextView)view.findViewById(R.id.group_item_reply_count);
			handleView.mTvLastReplyTime = (TextView)view.findViewById(R.id.group_item_time);
		}else{
			handleView = (HandleView)view.getTag();
		}
		initHandleView(handleView, topicData);
		initHandleViewListener(handleView, topicData);
		view.setTag(handleView);
		return view;
	}
	
	private void initHandleView(HandleView handleView, DouGroupTopicData data){
		handleView.mTvTitle.setText(data.mTitile);
		handleView.mTvGroup.setText(data.mGroupName);
		handleView.mTvAuthor.setText(data.mAuthor);
		handleView.mTvReplyCount.setText(String.format("回复(%s)", data.mReplyCount));
		handleView.mTvLastReplyTime.setText(data.mLastReplyTime);
	}
	
	private void initHandleViewListener(HandleView handleView, DouGroupTopicData data){
		// 跳到小组首页
		handleView.mTvGroup.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				
			}
		});
	}
	
	
	private class HandleView {
		public TextView mTvTitle;
		public TextView mTvGroup;
		public TextView mTvAuthor;
		public TextView mTvReplyCount;
		public TextView mTvLastReplyTime;
	}
	
}